﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace GVCSMTemplates
{
    public class CalculateTableInformationThreeFrames
    {
        public DataTable tableRowsForThreeScreenWith1SessionQ1(DataTable dt)
        {
            DataTable resultTable = new DataTable();
            resultTable = dt.Clone();
            resultTable.Clear();
            if (dt.Rows.Count < 4 && dt.Rows.Count > 0)
            {
                object[] iRow = dt.Rows[0].ItemArray;
                resultTable.Rows.Add(iRow);
            }
            else if (dt.Rows.Count > 3)
            {
                object[] iRow = dt.Rows[3].ItemArray;
                resultTable.Rows.Add(iRow);
            }

            return resultTable;
        }

        public DataTable tableRowsForThreeScreenWith2SessionQ1(DataTable dt)
        {
            DataTable resultTable = new DataTable();
            resultTable = dt.Clone();
            resultTable.Clear();
            object[] iRow = dt.Rows[13].ItemArray;
            resultTable.Rows.Add(iRow);
            return resultTable;
        }

        public DataTable retrieveTableForThreeScreenTemplateQ1(DataTable dt)
        {
            int rowCount = dt.Rows.Count;
            DataTable dtNormal = new DataTable();

            if (rowCount >= 14)
            {
                IniFile ini = new IniFile(@"c:\BOX\Signbox\played.ini");
                String value = ini.ReadValue("Three Screen Template Q1", "played");
                if (value == "played2")
                {
                    dtNormal = tableRowsForThreeScreenWith1SessionQ1(dt);
                    ini.WriteValue("Three Screen Template Q1", "played", "played1");
                }
                else
                {
                    dtNormal = tableRowsForThreeScreenWith2SessionQ1(dt);
                    ini.WriteValue("Three Screen Template Q1", "played", "played2");
                }
            }
            else
            {
                dtNormal = tableRowsForThreeScreenWith1SessionQ1(dt);
            }

            return dtNormal;
        }

        public DataTable tableRowsForThreeScreenWith1SessionQ2(DataTable dt)
        {
            DataTable resultTable = new DataTable();
            resultTable = dt.Clone();
            resultTable.Clear();
            if (dt.Rows.Count < 4 && dt.Rows.Count > 1)
            {
                object[] iRow = dt.Rows[1].ItemArray;
                resultTable.Rows.Add(iRow);
            }
            else if (dt.Rows.Count > 4)
            {
                object[] iRow = dt.Rows[4].ItemArray;
                resultTable.Rows.Add(iRow);
            }
            return resultTable;
        }

        public DataTable tableRowsForThreeScreenWith2SessionQ2(DataTable dt)
        {
            DataTable resultTable = new DataTable();
            resultTable = dt.Clone();
            resultTable.Clear();
            object[] iRow = dt.Rows[14].ItemArray;
            resultTable.Rows.Add(iRow);
            return resultTable;
        }

        public DataTable retrieveTableForThreeScreenTemplateQ2(DataTable dt)
        {
            int rowCount = dt.Rows.Count;
            DataTable dtNormal = new DataTable();

            if (rowCount >= 15)
            {
                IniFile ini = new IniFile(@"c:\BOX\Signbox\played.ini");
                String value = ini.ReadValue("Three Screen Template Q2", "played");
                if (value == "played2")
                {
                    dtNormal = tableRowsForThreeScreenWith1SessionQ2(dt);
                    ini.WriteValue("Three Screen Template Q2", "played", "played1");
                }
                else
                {
                    dtNormal = tableRowsForThreeScreenWith2SessionQ2(dt);
                    ini.WriteValue("Three Screen Template Q2", "played", "played2");
                }
            }
            else
            {
                dtNormal = tableRowsForThreeScreenWith1SessionQ2(dt);
            }

            return dtNormal;
        }

        public DataTable tableRowsForThreeScreenWith1SessionQ3(DataTable dt)
        {
            DataTable resultTable = new DataTable();
            resultTable = dt.Clone();
            resultTable.Clear();
            if (dt.Rows.Count < 4 && dt.Rows.Count > 1)
            {
                object[] iRow = dt.Rows[2].ItemArray;
                resultTable.Rows.Add(iRow);
            }
            else if (dt.Rows.Count > 5)
            {
                object[] iRow = dt.Rows[5].ItemArray;
                resultTable.Rows.Add(iRow);
            }
            return resultTable;
        }

        public DataTable tableRowsForThreeScreenWith2SessionQ3(DataTable dt)
        {
            DataTable resultTable = new DataTable();
            resultTable = dt.Clone();
            resultTable.Clear();
            object[] iRow = dt.Rows[15].ItemArray;
            resultTable.Rows.Add(iRow);
            return resultTable;
        }

        public DataTable retrieveTableForThreeScreenTemplateQ3(DataTable dt)
        {
            int rowCount = dt.Rows.Count;
            DataTable dtNormal = new DataTable();

            if (rowCount >= 16)
            {
                IniFile ini = new IniFile(@"c:\BOX\Signbox\played.ini");
                String value = ini.ReadValue("Three Screen Template Q3", "played");
                if (value == "played2")
                {
                    dtNormal = tableRowsForThreeScreenWith1SessionQ3(dt);
                    ini.WriteValue("Three Screen Template Q3", "played", "played1");
                }
                else
                {
                    dtNormal = tableRowsForThreeScreenWith2SessionQ3(dt);
                    ini.WriteValue("Three Screen Template Q3", "played", "played2");
                }
            }
            else
            {
                dtNormal = tableRowsForThreeScreenWith1SessionQ3(dt);
            }

            return dtNormal;
        }
    }
}